<div style="background-color:#FFF">
<?php
if($handle=opendir("plugin/pixbox/images/")){
  while(false!==($file=readdir($handle))){
    if(substr($file,0,1)!='.'){
      echo'
<a href="#" onclick="getpixbox(this);">',$file,'</a><br />';

    }
  } closedir($handle); }

function scalepic($pic,$percent){
  $percent*=0.01;
  list($width,$height)=getimagesize($pic);
  $new_width=$width*$percent;
  $new_height=$height*$percent;
  $image_p=imagecreatetruecolor($new_width, $new_height);
  $image=imagecreatefromjpeg($pic);
  imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);
  return$image_p;
}


function addpic($pid='image'){
  $file=basename($_FILES[$pid]['name']);
  $tmp=$_FILES[$pid]['tmp_name'];
  //$pixbox=$_POST[$pixbox];
  $target_path='../media/pixbox/'.$pid.'/';
  $target_file=$target_path.$file;
  if(!is_dir($target_path)){ mkdir($target_path.$pixbox); }
  if(move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) {
    //echo "The file ". $file . " has been uploaded";
	$image_p=scalepic($target_file);
   	$thumbs=$target_path.'thumbs/';
	if(!is_dir($thumbs)){ mkdir($thumbs); }
	$thumbs_file=$thumbs.$file;
	imagejpeg($image_p,$thumbs_file, 95);


	echo pimg($target_file);
	echo pimg ($thumbs_file);

	//header("Location:pixbox.php");
	//echo('<meta http-equiv="refresh" content="20">');
	//header('Content-type: image/jpeg');
	//return array($target_file,$thumbs_file)
} else{
	echo "There was an error uploading the file, please try again in 12 seconds or press the BACK or REFRESH button of your browser!";
	echo('<meta http-equiv="refresh" content="12">');
	//return array(False,False);
}

}
/*$testdb=pdbopen('localhost:3307','cultuuradm','test','cultuurdb');
$fields=pdbqueryfields();
pdbclose($testdb);*/
?>
</div>
<div id="pixdiv">
<img src="" alt="pixbox" id="pixbox" width="200" height="200" onclick="pixpop(this);"/>
<div id="pixlabel">label</div>
<script type="text/javascript">//<![CDATA[

function pixpop(el){
  if(window.popped){
    el.width=200;
    el.height=200;
    el.style.position='static';
    window.popped=false;
  }
  else{
    el.width=el.naturalWidth;
    el.height=el.naturalHeight;
    el.style.position='absolute';
    el.top=(windowheight()*0.5)-(el.naturalHeight*0.5);
    el.left=(windowwidth()*0.5)-(el.naturalWidth*0.5);;
    window.popped=true;
  }
}

function windowwidth() {
  var myWidth=0;
  if(typeof(window.innerWidth)=='number'){
    myWidth=window.innerWidth;     //Non-IE
  }
  else if(document.documentElement && document.documentElement.clientWidth){
    myWidth=document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
  }
  else if(document.body && document.body.clientWidth){
    myWidth=document.body.clientWidth;     //IE 4 compatible
  }
  return myWidth;
}

function windowheight() {
  var myHeight=0;
  if(typeof(window.innerHeight)=='number'){
    myHeight=window.innerHeight;    //Non-IE
  }
  else if(document.documentElement && document.documentElement.clientHeight){
    myHeight=document.documentElement.clientHeight;    //IE 6+ in 'standards compliant mode'
  }
  else if(document.body && document.body.clientHeight){
    myHeight=document.body.clientHeight;     //IE 4 compatible
  }
  return myHeight;
}

function getpixbox(el){
  ajaxjs('plugin/pixbox/cms/show.php?js=1&pixbox='+el.innerHTML);
  ajax('pixboxlist','plugin/pixbox/cms/show.php?pixbox='+el.innerHTML);
  nextpic(); //function fetched thru ajax (runs too late)
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function ajaxjs(cmd){
  if (window.XMLHttpRequest){ var xmlhttp=new XMLHttpRequest(); }
  else{ var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
      eval(xmlhttp.responseText); }}
  xmlhttp.open("GET",cmd,true);
  xmlhttp.send();
}

function ajax(adiv,cmd){
  if (window.XMLHttpRequest){ var xmlhttp=new XMLHttpRequest(); }
  else{ var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
      document.getElementById(adiv).innerHTML=xmlhttp.responseText; }}
  xmlhttp.open("GET",cmd,true);
  xmlhttp.send();
}
//]]></script>

<?php
/*switch($page){

case'new':
  include'plugin/pixbox/cms/newpixbox.php';
  break;

case'single':
  include'plugin/pixbox/cms/cmssingle.php';
  break;
}*/
?>
<div id="pixboxlist"></div>
</div>

